import axios from "axios";
const instance = axios.create({
    baseURL:'http://kumanxuan1.f3322.net:8881/cms'
})

// 添加请求拦截器
instance.interceptors.request.use(function (config) {
    console.log('请求拦截器');
    // config.headers.token = 123;
    let token =localStorage.getItem('x-auth-token')
    if(token){
      config.headers['x-auth-token'] = token; 
    }
    return config;
  }, function (error) {
    return Promise.reject(error);
  });



// 添加响应拦截器
instance.interceptors.response.use(function (response) {
    console.log('响应拦截器');
    if(response.data.code !=0&&response.data.code !=400 && response.data.code !=407){
      alert('[拦截器]'+response.data.message);
      return;
    }
    return response.data;
    // return response;
  }, function (error) {
    return Promise.reject(error);
  });
export default instance